package cn.yeziji.forum.controller;

import cn.yeziji.forum.common.ForumResult;
import cn.yeziji.forum.dao.intf.ForumAnswerDao;
import cn.yeziji.forum.dto.answer.AnswerDTO;
import cn.yeziji.forum.utils.ForumResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 回复控制器
 *
 * @author gzkemays
 * @since 2022/11/14 4:25 PM
 */
@RestController
@RequestMapping("/answer")
public class ForumAnswerController {
  @Resource ForumAnswerDao answerDao;

  @GetMapping("/list/{id}")
  public ForumResult list(@PathVariable(name = "id") Integer id) {
    return ForumResultUtils.ok(answerDao.list(id));
  }

  @PostMapping("/reply")
  public ForumResult reply(@RequestBody @Valid AnswerDTO dto) {
    answerDao.replay(dto);
    return ForumResultUtils.ok();
  }
}
